﻿using System;
using System.Web.Mvc;

using MVCThemes.Interfaces;
using System.Web.Routing;

namespace mvcForum.Web.Extensions {

	public static class UrlHelperExtensions {

		private static String GetTheme() {
			// Get the theme provider!
			IThemeProvider provider = DependencyResolver.Current.GetService<IThemeProvider>();
			// Did we get one?
			if (provider != null) {
				// Yes, let's get the theme then!
				return provider.GetTheme();
			}
			return String.Empty;
		}

		public static String GetThemeBaseUrl(this UrlHelper url) {
			String theme = GetTheme();
			if (!String.IsNullOrWhiteSpace(theme)) {
				// Let's build the URL then!
				return String.Format("~/themes/{0}/", theme);
			}
			// No dice, let's just return the usual views base path.
			return "~/";
		}

		/// <summary>
		/// Extension method that returns the url to the given forum.
		/// </summary>
		/// <param name="url">The UrlHelper class.</param>
		/// <param name="forumId">Id of the forum.</param>
		/// <param name="forumName">name of the forum.</param>
		/// <returns>The url to the given forum.</returns>
		public static String Forum(this UrlHelper url, Int32 forumId, String forumName) {
			return UrlHelper.GenerateUrl("ShowForum", null, null, null, null, null, new RouteValueDictionary { { "id", forumId }, { "title", forumName.ToSlug() } }, url.RouteCollection, url.RequestContext, false);
		}
	}
}